﻿using System;
using System.Text;

class EncryptionKey
{    
    static void Main()
    {
        string text = "01.02.2013 – After shattering Garry Kasparov's legendary 2851 rating record " + 
            "Norwegian chess genius Magnus Carlsen still continues to climb. With his +7 score in Wijk aan Zee " +
            "he has added eleven more points to his stratospheric Elo and is now 62 points (!) above his nearest rival. " +
            "Who happens to be Vladimir Kramnik, father of Vadim, born last Monday in Paris. February rankings.";
        string key = "Kasparov";
        string encryptedText = EncryptText(text, key);
        string decryptedText = DecryptText(encryptedText, key);

        Console.WriteLine("ENCRYPTED TEXT:\n");
        Console.WriteLine(encryptedText);
        Console.WriteLine("\nDECRYPTED TEXT:\n");
        Console.WriteLine(decryptedText);
        Console.WriteLine();
    }

    static string EncryptText(string text, string key)
    {
        int textLength = text.Length;
        StringBuilder encryptedText = new StringBuilder(textLength);

        for (int index = 0; index < textLength; index++)
        {
            encryptedText.Append((char)(text[index] ^ key[index % key.Length]));
        }

        return encryptedText.ToString();
    }

    static string DecryptText(string text, string key)
    {
        return EncryptText(text, key);
    }
}
